<?php
require_once('kernel.inc');
include_once(LIBRARIES . '/FastJSON.class.inc');
define("MYID", $MECCANO->GetModuleId($moduleid));
$input     = false;

if($AUTH->logedstatus == true && $AUTH->permission == 'system')
{
   $CONTENT = new kernel('content');

   switch($event)
   {
      case 6:
         $CONTENT->SetParams('language='.$lang);
         $vars = $CONTENT->View($id);
         break;
         
      case 7:
         $MECCANO->SetParams('language='.$lang);
         $vars = $MECCANO->GetTree($category);
         break;
      
      case 8:
         if($id != false)
         {
            if(!in_array($lang, $MECCANO->system['lang']))
            {
               $lang = $MECCANO->system['lang'][0];
            }

            $DB->sql = 'SELECT id FROM meccano_content WHERE id=' . $id . ' AND lang="' . $lang . '"';
            $DB->DB_Query();
            if($DB->DB_GetRows() > 0)
            {
               $DB->DB_QueryBuilder('UPDATE meccano_content SET title = "%s", metawords = "%s", metadescr = "%s", content = "%s" WHERE id = %i AND lang = "%s"', array($_POST['cont_title'], $_POST['cont_metawords'], $_POST['cont_description'], $_POST['cont_content'], $id, $lang));
            } else 
            {
               $DB->DB_QueryBuilder('INSERT INTO meccano_content (id, title, metawords, metadescr, content, lang) VALUES (%i, "%s", "%s", "%s", "%s", "%s")', array($id, $_POST['cont_title'], $_POST['cont_metawords'], $_POST['cont_description'], $_POST['cont_content'], $lang));
            }

            $make = $DB->DB_Query();
            $SMARTY->assign('make', $make);
         }

      default:
         $SMARTY->display("admin.content.tpl.html");
         exit();
   }
   
   if($event != false && $vars != false)
   {
      echo FastJSON::encode($vars);
   } else
   {
      echo 0;
   }

} else
{
   echo $AUTH->frame_redirector();
}